from timeit import default_timer as timer

import cv2
from random import randint
from time import sleep
import json


class Detector:
    def __init__(self):
        self.image = cv2.imread("./sources/BachongShenzi.png")
        self.counter = 0
        with open("tests/run_system/objs.json") as f:
            self.objs = json.load(f)

    def set_stream(self, stream_path):
        self.streamer = stream_path

    def get_frame(self):
        self.counter += 1
        return self.image

    def check_stream(self):
        return True

    def detect(self, frame, save_img=False, neth=640, netw=640):

        detected_objs = self.objs[self.counter]
        time_cost = randint(400, 800) / 1000
        sleep(time_cost)
        return self.image, detected_objs
